using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Silverlight.Testing;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SLNGP.Core.Fitness;
using SLNGP.Core.Individuals;
using SLNGP.Core.Test;

namespace SLNGP.Test.CoreTests.Fitness
{
    [TestClass]
    [Tag("SingleIndivdualFitnessFunction")]
    public class SingleIndivdualFitnessFunction_Test : UnitTestBase<ISingleFitnessFunction<int>, SingleIndivdualFitnessFunction<int>>
    {
        #region UnitTestBase methods
        [ClassInitialize]
        public static void ClassInitialize(TestContext testContext)
        {
            UnitTestBase<ISingleFitnessFunction<int>, SingleIndivdualFitnessFunction<int>>.ClassInitialize(testContext);
        }

        [ClassCleanup]
        public static void ClassCleanup()
        {
            UnitTestBase<ISingleFitnessFunction<int>, SingleIndivdualFitnessFunction<int>>.ClassCleanup();
        }

        [TestInitialize]
        public override void TestInitialize()
        {
            base.TestInitialize();
        }

        [TestCleanup]
        public override void TestCleanup()
        {
            base.TestCleanup();
        }
        #endregion UnitTestBase methods

        [TestMethod]
        public void GenerationWith1IndividualAndHasFitnessFunctionOf20_Evaluate_SetsIndividualFitnessTo20()
        {
            // state - GenerationWith1IndividualAndHasFitnessFunctionOf20
            curElement.EvaluateFunction = (x) => 20;
            var mock = mocks.DynamicMock<IIndividual>();
            var stubGeneration = new Generation() { mock };

            // Expectation - SetsIndividualFitnessTo20
            using (mocks.Record())
                mock.Fitness = 20;

            // action - Evaluate
            curElement.Evaluate(stubGeneration);

            // verify
            mocks.VerifyAll();
        }
    }
}
